<!--
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<div class="import" fileDragDrop (fileDragDropFileAccepted)="fileAccepted($event)"
     (fileDragDropFileRejected)="fileRejected($event)"
     (fileDragDropDragOver)="fileDetected($event)" (fileDragDropDragLeave)="fileLeft($event)"
     [maxFileSize]="maxFileSize" [supportedFileTypes]="supportedFileTypes">
  <div class="modal-header">
    <h1>Add a file</h1>
    <button id="add-file_exit" class="icon modal-exit" (click)="activeModal.dismiss()">
      <svg class="ibm-icon" aria-hidden="true">
        <use xlink:href="#icon-close_new"></use>
      </svg>
    </button>
  </div>
  <section class="modal-body">
    <span>Upload a file from your computer...</span>
    <file-importer (fileAccepted)="fileAccepted($event)" (fileRejected)="fileRejected($event)" [expandInput]="expandInput"
                   [maxFileSize]="maxFileSize" [supportedFileTypes]="supportedFileTypes" [ngClass]="{'expandFile': expandInput}" [svgName]="'#icon-CTO_JS_Upload'"></file-importer>
    <div class="chosen-file" *ngIf="expandInput && currentFile">
      <div class="file-info">
        <div class="flex-container">
          <svg class="ibm-icon" aria-hidden="true">
            <use xlink:href="#icon-ACL_File" *ngIf="fileType==='acl'"></use>
            <use xlink:href="#icon-CTO_File" *ngIf="fileType==='cto'"></use>
            <use xlink:href="#icon-JS_File" *ngIf="fileType==='js'"></use>
            <use xlink:href="#icon-MD_File" *ngIf="fileType==='md'"></use>
            <use xlink:href="#icon-QRY_File" *ngIf="fileType==='qry'"></use>
          </svg>
          <div class="file-title">
            <div class="title">{{currentFileName}}</div>
            <div *ngIf="fileType==='cto'">
              <span>{{currentFile.getAssetDeclarations().length}} Assets</span>
              <span>{{currentFile.getParticipantDeclarations().length}} Participants</span>
              <span>{{currentFile.getTransactionDeclarations().length}} Transactions</span>
            </div>
            <div *ngIf="fileType==='js'">
              <span>{{currentFile.getFunctionDeclarations().length}} Functions</span>
            </div>
          </div>
        </div>
        <div>
          <button role="button" type="button" class="action" (click)="removeFile()">Remove File</button>
        </div>
      </div>
    </div>
    <form class="file-types-list" #f="ngForm" *ngIf="!expandInput">
      <div class="file-types-list-item">
        <input type="radio" id="file-type-cto" name="file-type" [(ngModel)]="fileType" value="cto"
               (change)="changeCurrentFileType()">
        <label class="radio-label" for="file-type-cto">Model File (.cto)</label>
        <div class="description">
          Define Assets, Participants and Transactions using Hyperledger Composer modelling langauge.
        </div>
      </div>
      <div class="file-types-list-item">
        <input type="radio" id="file-type-js" name="file-type" [(ngModel)]="fileType" value="js"
               (change)="changeCurrentFileType()">
        <label class="radio-label" for="file-type-js">Script File (.js)</label>
        <div class="description">
          Define the logic of transaction executions using JavaScript.
        </div>
      </div>
      <div class="file-types-list-item">
        <input type="radio" id="file-type-qry" name="file-type-qry" [(ngModel)]="fileType" value="qry"
               (change)="changeCurrentFileType()">
        <label class="radio-label" for="file-type-qry">Query File (.qry)</label>
        <div class="description">
          Define the queries in here (Note: you can only have 1 of these per .bna).
        </div>
      </div>
      <div class="file-types-list-item">
        <input type="radio" id="file-type-acl" name="file-type-acl" [(ngModel)]="fileType" value="acl"
               (change)="changeCurrentFileType()">
        <label class="radio-label" for="file-type-acl">Access Control File (permissions.acl)</label>
        <div class="description">
          Define your access controls here (Note: you can only have 1 of these per .bna).
        </div>
      </div>
    </form>
  </section>
  <footer>
    <button id="add-file_cancel" type="button" class="secondary" (click)="activeModal.dismiss();">
      <span>Cancel</span>
    </button>
    <button id="add-file_confirm"type="button" class="primary" (click)="activeModal.close(currentFile);" [disabled]="!currentFile">
      <span>Add</span>
    </button>
  </footer>
</div>
